package info.xiao.dataStructrue.array;

import java.util.Arrays;

/**
 * @Classname FindErrorNums
 * @Description 错误的集合
 * @Href https://leetcode.cn/problems/set-mismatch/
 * @Date 2023/3/16 10:54
 * @Created by 晓龙Oba
 */
public class FindErrorNums {
    public static void main(String[] args) {
        int[] nums = {1, 5, 3, 2, 2, 7, 6, 4, 8, 9};
        nums = findErrorNums(nums);
        System.out.println(nums);
    }

    private static int[] findErrorNums(int[] nums) {
        int[] result = new int[2];
        // 首先 我们需要判断集合是否有序
        Arrays.sort(nums);
        int tmp = nums[0];
        int sum = (1 + nums.length) * nums.length / 2;
        for (int i = 0; i < nums.length - 1; i++) {
            tmp += nums[i + 1];
            if (nums[i] == nums[i + 1]) {
                result[0] = nums[i];
            }

        }
        result[1] = result[0] + (sum - tmp);
        return result;
    }
}
